<?php

namespace app\common\validate;

use think\Validate;

class TeacherJob extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'user_id|用户' => 'require',
        'give_timesec|接单期限' => 'require|in:half_hour,a_hour,three_day,a_day,a_week',
        'addr|地址' => 'areaRule',
        'mobile|手机号' => 'require|mobile',
        'student|学生姓名' => 'require|chs|length:1,5',
        'sex|性别' => 'require|in:男,女',
        'grade|年级' => 'require',
        'subject|科目' => 'require',
        'state|学生基本情况' => 'require|length:2,100',
        'learn_date|上课时间' => 'require|date',
        'learn_time|具体时间' => 'require',
        'teacher_sex|性别' => 'require|in:男,女',
        'teacher_type|老师类型' => 'require',
        'demand|对老师的要求' => 'require|length:2,100',
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'user_id.require' => '用户不能为空',
        'give_timesec.require' => '请选择接单期限',
        'addr.areaRule' => '地址不能为空',
        'mobile.require' => '手机号不能为空',
        'student.length' => '学生姓名的长度在1-5之间',
        'sex.require' => '性别不能为空',
        'grade.require' => '年级不能为空',
        'subject.require' => '科目不能为空',
        'state.length' => '学生基本情况的长度在2-100之间',
        'learn_date.require' => '上课时间不能为空',
        'learn_time.require' => '具体时间不能为空',
        'teacher_sex.require' => '老师性别不能为空',
        'teacher_type.require' => '老师类型不能为空',
        'demand.length' => '对老师的要求在2-100之间',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [
            'user_id',
            'give_timesec',
            'addr',
            'mobile',
            'student',
            'sex',
            'grade',
            'subject',
            'state',
            'learn_date',
            'learn_time',
            'teacher_sex',
            'teacher_type',
            'demand',
        ],
        'user' => [
            'addr',
            'mobile',
            'student',
            'sex',
            'grade',
            'subject',
            'state',
        ],
    ];


    function mobile($mobile)
    {
        $pattern = "/^1[3-9]\d{9}$/";
        if (!preg_match($pattern, $mobile)) {
            return FALSE;
        }
        return TRUE;
    }

    public function areaRule($value)
    {
        if(!$value[0] || !$value[1] || !$value[2] || !$value[3]){
            return FALSE;
        }
        return TRUE;
    }
}
